package org.tokaf;

import java.util.Comparator;

/**
 * <p> MyTopKCompareValues compares two TopKElements by their ratings. </p> <p>
 * Copyright (c) 2006 </p> <p>
 * @author Alan Eckhardt
 * @version 1.0
 */
public class MyTopKCompareValues implements Comparator {
	boolean descending = true;

	public MyTopKCompareValues(boolean descending) {
		this.descending = descending;
	}

	public MyTopKCompareValues() {
	}

	public int compare(Object o1, Object o2) {
		if (((TopKElement) o1).rating > ((TopKElement) o2).rating) {
			if (descending)
				return -1;
			else
				return 1;
		} else if (((TopKElement) o1).rating < ((TopKElement) o2).rating) {
			if (descending)
				return 1;
			else
				return -1;
		} else
			return 0;
	}
}
